<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd()"
          v-hasPermi="['business:order:list']">新增</el-button>
      </el-col>
     <!-- <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['business:order:list']">删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">刷新</el-button>
      </el-col>
    </el-row>
    <el-table :data="dataList" v-loading="loading" @selection-change="handleSelectionChange" style="width: 100%;"
      row-key="id">
      <!-- <el-table-column type="selection" width="50" align="center" /> -->
      <el-table-column type="index" label="序号" width="60"></el-table-column>
      <el-table-column prop="name" label="商品类型" :show-overflow-tooltip="true" />
      <el-table-column prop="picturePath" label="商品类型缩略图" width="">
        <template slot-scope="scope">
          <img v-lazy="imageApi + scope.row.picturePath" style="height:40px" />
        </template>
      </el-table-column>
      <el-table-column label="是否推荐" prop="recommend" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.recommend == 1">推荐</span>
          <span v-else>不推荐</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="status" width="100">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 1">使用中</span>
          <span v-else>未启用</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" width="300">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-plus" @click="handleAdd(scope.row)">新增</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['business:order:list']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['business:order:list']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>
<script>
  import {
    mapGetters
  } from 'vuex'
  import {
    page,
    deleteById,
    addOrUpdate,
    getType
  } from "@/api/business/goods/type";
  import AddOrUpdate from './addOrUpdate'
  export default {
    dicts: ['order_status'],
    computed: {
      ...mapGetters(["sysUser"]),

    },
    data() {
      return {
        franchiseeList: [],
        loading: true,
        imageApi: process.env.VUE_APP_IMAGE_BASE_URL,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        // 总条数
        total: 0,
        //表格数据
        dataList: [],
        // 弹出层标题
        title: "",
        // 表单参数
        // 显示搜索条件
        showSearch: true,
        form: {},
        // 日期范围
        dateRange: [],
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          search: {
            keyword: '',
            franchiseeId: ''
          }
        },
        dataList: [],
        rules: {},
        addOrUpdateVisible: false,
        dataDate: [],
      }
    },
    components: {
      AddOrUpdate
    },
    created() {
      this.getDataList();
      this.initPage();
    },
    methods: {
      onDateChange(e) {
        const search = this.queryParams.search;
        search.startDate = e[0];
        search.endDate = e[1];
        this.queryParams.search = search;
      },
      initPage() {

      },
      // 获取数据列表
      getDataList() {
        this.loading = true;
        getType({
          status: 0
        }).then(response => {
          this.dataList = response.data;
          this.loading = false;
        }).catch(res => {
          this.loading = false
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getDataList();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.userId);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd(e) {
        const p = e ? e : {
          level: -1,
          id: 0
        }
        this.addOrUpdateVisible = true;
        this.title = "添加";
        this.$nextTick(() => {
          this.$refs.addOrUpdate.onAdd(p)
        })
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.addOrUpdateVisible = true;
        this.title = "修改";
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(row)
        })
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('确定要删除选中的数据项？').then(function() {
          return deleteById(row);
        }).then(() => {
          this.getDataList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      resetQuery() {
        this.dataDate = [];
        this.resetForm("queryForm");
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          search: {
            keyword: '',
            franchiseeId: ''
          }
        };
        this.getDataList()
      }
    }
  }
</script>
